package com.lsu.app.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lsu.app.bean.Talk;
import com.lsu.app.service.TalkService;
import com.lsu.app.mapper.TalkMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 *
 * @description 针对表【talk(话题)】的数据库操作Service实现
 * @Date 2023-10-18 20:27:11
 * @author hjj
 */
@Service
public class TalkServiceImpl extends ServiceImpl<TalkMapper, Talk> implements TalkService{
    private TalkMapper mapper;

    public TalkServiceImpl(TalkMapper mapper) {
        this.mapper = mapper;
    }

    @Override
    public void updateTalkHeat(Integer id, Integer amount) {
        mapper.updateTalkHeat(id,amount);
    }

    @Override
    public String getTitleById(Integer id) {
        return mapper.getTitleById(id);
    }

    @Override
    public Integer getTypeIdByTypeName(String typeName) {
        return mapper.getTypeIdByTypeName(typeName);
    }

    @Override
    public List<String> getAllTypeName() {
        return mapper.getAllTypeName();
    }

    @Override
    public String getTypeNameByType(Integer type) {
        return mapper.getTypeNameByType(type);
    }

    @Override
    public Integer getHostIdByTalkId(Integer id) {
        return mapper.getHostIdByTalkId(id);
    }

    @Override
    public List<Talk> getCourseTalksByCourseId(Integer courseId) {
        return mapper.getCourseTalksByCourseId(courseId);
    }

    @Override
    public List<Integer> getCourseIdsByUserId(Integer userId) {
        return mapper.getCourseIdsByUserId(userId);
    }

    @Override
    public void insertUC(Integer userId, Integer courseId) {
        mapper.insertUCT(userId,courseId, LocalDate.now().toString());
    }

    @Override
    public void deleteUCT(Integer courseId) {
        mapper.deleteUCT(courseId);
        mapper.deleteByCourseId(courseId);
    }

    @Override
    public void stuInsert(Integer userId, Integer courseId) {
        if(mapper.getOneByUserIdAndCourseId(userId, courseId)==0){
            mapper.insertUCT(userId,courseId,LocalDate.now().toString());
        }else {
            mapper.updateUCTofTime(LocalDate.now().toString(),userId,courseId);
        }
        //检查其他时间是否超过三十天
        mapper.deleteOverTime(userId,LocalDate.now().plusDays(-30).toString());
    }
}




